<?php

/**
 * Description of AddUserForm
 *
 * @author Mina
 */
class AddUserForm extends UserForm
{

    public function configure()
    {
        parent::configure();
        $this->getWidget('role_categories_list')->addOption('expanded', true);

        $fields = array('username', 'name', 'email', 'phone', 'mobile',
            'address', 'photo', 'statues', 'need_check');
        if($this->isNew())
        {
            array_push($fields, 'password', 're_password') ;
        }
        // check if login user is superAdmin credential
        $sfUser = $this->getOption('sfUser');
        if( $sfUser && $sfUser instanceof sfUser)
        {
            if($sfUser->hasCredential('superAdmin'))
            {
                array_push($fields,'role_id');
            }
        }
        else
        {
            throw new InvalidArgumentException('you must send sfUser option');
        }
        $this->useFields($fields);
    }

}
